import {
  Column,
  Entity,
  ManyToMany,
  PrimaryGeneratedColumn,
  JoinTable,
} from 'typeorm';
import { FlavorEntity } from './flavor.entity';

@Entity() //sql表名默认会使用类名
export class CoffeeEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  brand: string;

  // @Column('json', { nullable: true }) //将数组存储为json
  @JoinTable()
  @ManyToMany(() => FlavorEntity, (flavor) => flavor.coffees, {
    cascade: true, // ['insert'] 级联插入
  })
  flavors: FlavorEntity[];
}
